package com.example.utils;

import java.util.List;

public class SensitiveWordFilter {
    private List<String> sensitiveWords;

    public SensitiveWordFilter(List<String> sensitiveWords) {
        this.sensitiveWords = sensitiveWords;
    }

    public String filter(String text) {
        if (sensitiveWords == null || text == null) return text;

        for (String word : sensitiveWords) {
            text = text.replaceAll("(?i)" + word, "***"); // 不区分大小写替换
        }
        return text;
    }
}